package com.xzlcPT.service.impl;

import com.github.pagehelper.PageHelper;
import com.util.PageBean;
import com.xzlcPT.bean.XzPostionBrowse;
import com.xzlcPT.dao.XzPostionBrowseMapper;
import com.xzlcPT.service.XzPostionBrowseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2017/7/27.
 */
@Service("postionBrowseService")
public class XzPostionBrowseServiceImpl implements XzPostionBrowseService {

    @Autowired
    XzPostionBrowseMapper postionBrowseMapper;

    @Override
    public int insertPostionBrowse(Long postionId, Long memberId) {
        int count = postionBrowseMapper.selectCountByMemberId(memberId);
        XzPostionBrowse postionBrowse = postionBrowseMapper.selPCinfo(postionId);
        postionBrowse.setMemberId(memberId);
        postionBrowse.setBrowseTime(new Date());
        if (count >= 10) {
            postionBrowseMapper.delLast(memberId);
        }
        return postionBrowseMapper.insert(postionBrowse);
    }

    @Override
    public List<XzPostionBrowse> selPostionBrowse(Long memberId) {
        return postionBrowseMapper.selectByMemberId(memberId);
    }

    @Override
    public PageBean<XzPostionBrowse> selPostionBrowse(int page, int rows, Long memberId) {
        PageHelper.startPage(page, rows);
        List<XzPostionBrowse> PostionBrowse = postionBrowseMapper.selectByMemberId(memberId);
        return new PageBean<>(PostionBrowse);
    }

    @Override
    public PageBean<XzPostionBrowse> selPosBrowByPosId(int page, int rows, Long postionId) {
        PageHelper.startPage(page, rows);
        List<XzPostionBrowse> PostionBrowse = postionBrowseMapper.selByPostionId(postionId);
        return new PageBean<>(PostionBrowse);
    }

    @Override
    public int selectCountByPostionId(Long postionId) {
        return postionBrowseMapper.selectCountByPostionId(postionId);
    }

}
